home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0574.ZIP
/
RNEWS.C
< prev
next >
Wrap
Text File
|
1986-08-12
|
15KB
|
611 lines
/*
$Source: BOB/USENET/rnews.c%v $
This file is part of the UN*X Gateway Fido/UNIX code.
This implements reading UNIX messages and placing them
into the proper message bases. Files, USENET messages,
and mail messages are all handled here.
*/
/*
* $Log: rnews.c $
* Revision 1.1 85/12/10 01:46:22 rch
* Initial revision
*
*/
#include <dos.h>
#include <stdio.h>
#include <fcntl.h>
#include <stat.h>
#define MAX_SIZE 9000L
#define TEMPNAME "JUNKXXXX.XXX"
#define MSGPRIVATE 1 /* private message */
#define MSGBROAD 2 /* broadcast message */
#define MSGREAD 4 /* read by addressee */
#define MSGSENT 8 /* sent OK (remote) */
#define MSGFILE 16 /* file attached to msg */
#define MSGFWD 32 /* being/was forwarded */
#define MSGORPHAN 64 /* unknown dest node */
#define MSGKILL 128 /* Kill when sent */
char *template = TEMPNAME;
static struct {
char rsvd[21];
char attr;
long ftime;
long fsize;
char fname[13];
} sbuf, sbuf1;
struct _msg {
char from[36];
char to[36];
char subj[72];
char date[20];
int times;
int dest;
int orig;
int cost;
int orig_net;
int dest_net;
int caca[4];
unsigned reply;
int attr;
int up;
} mess_head;
main (argc, argv)
int argc;
char *argv[];
{
extern char *mktemp(), *fgets ();
char line[BUFSIZ], *tmpfile, t1[BUFSIZ];
int from_file;
char datestamp[20];
char newsgroups[BUFSIZ];
char bang[3], rnews[128];
char filename[80], *underscore, *t;
int rm = 1;
int j, k, a, q, got_blank;
long size, i;
extern char *index ();
FILE *input, *output;
date ("%d %n %y ", datestamp);
time ("%h:%m:%s", &datestamp[11]);
strcpy (mess_head.date, datestamp);
mess_head.times = 0;
mess_head.orig = 101;
mess_head.cost = 0;
mess_head.orig_net = 132;
mess_head.reply = 0;
mess_head.up = 0;
printf ("\n\n***************** %s ********************\n\n", datestamp);
k = 1;
/* while (--argc) */
{
a = 0;
j = 1;
filedir (argv[k], a++, filename);
if (filename[0] == '\0')
printf ("******* No files match %s\n", argv[k]);
/* while (filename[0] != '\0') */
{
if ((input = fopen (filename, "r")) == NULL)
{
printf ( "******* Not able to open %s\n", filename);
/* filedir (argv[k], 0, filename);
for (q = 1; q < a; q++)
filedir (argv[k], q, filename);
filedir (argv[k], a++, filename);
continue; */
exit (1);
}
printf ("******* Processing %s ********\n", filename);
from_file = 1;
while (!feof(input))
{
if (from_file)
{
if (fscanf (input, "%s %s %ld", bang, rnews, &size) == EOF)
break;
if (getc (input) == EOF)
break;
}
else
if (sscanf (line, "%s %s %ld", bang, rnews, &size) == EOF)
break;
printf ("Processing article number %d\n", j++);
strcpy (template, TEMPNAME);
tmpfile = mktemp (template);
output = fopen (tmpfile, "w");
mess_head.subj[0] = '\0';
got_blank = 0;
for (i = 0L; i < size; i += (long) strlen (line))
{
from_file = 1;
if (fgets (line, BUFSIZ, input) == NULL)
break;
if (strncmp (line, "Newsgroups: ", 12) == 0)
strcpy (newsgroups, &line[12]);
if (strncmp (line, "Subject: ", 9) == 0)
strncpy (mess_head.subj, &line[9], 70);
if (strncmp (line, "#! ", 3) == 0)
{
from_file = 0;
break;
}
if (!got_blank)
if (sscanf (line, "%s:", t1) != 1)
got_blank = 1;
else
if (strncmp (line, "Path: ", 6) == 0)
fprintf (output, "%s", line);
else if (strncmp (line, "From: ", 6) == 0)
fprintf (output, "%s", line);
else if (strncmp (line, "Date: ", 6) == 0)
fprintf (output, "%s", line);
else
line[0] = '\0';
if (got_blank)
fprintf (output, "%s", line);
}
fclose (output);
if (strncmp (rnews, "FILE", 4) == 0)
{
printf (" Attempting to create %s\n", &rnews[5]);
filecopy (tmpfile, &rnews[5], 1);
unlink (tmpfile);
}
else
if (strncmp (rnews, "MAIL", 4) != 0)
if (size > MAX_SIZE)
{
printf ("Message too large: %ld bytes is larger than max %ld\n",
size, MAX_SIZE);
unlink (tmpfile);
}
else if (strncmp (mess_head.subj, "cancel ", 7) == 0)
{
printf ("message was a cancel message\n");
unlink (tmpfile);
}
else
{
strcpy (mess_head.from, "Usenet");
strcpy (mess_head.to, "All");
mess_head.dest = 101;
mess_head.attr = 256;
mess_head.dest_net = 132;
change_name (tmpfile, newsgroups);
}
else
{
strcpy (mess_head.from, "Usenet");
if (sscanf (&rnews[5], "%d!%d!%s", &mess_head.dest_net,
&mess_head.dest, mess_head.to) != 3)
sscanf (&rnews[5], "%d/%d!%s", &mess_head.dest_net,
&mess_head.dest, mess_head.to);
underscore = index (mess_head.to, '_');
mess_head.attr = MSGKILL + MSGPRIVATE + 256;
while (underscore != NULL)
{
*underscore = ' ';
++underscore;
underscore = index (underscore, '_');
}
t = mess_head.to;
*t = toupper (t[0]);
(void) strlower (&t[1]);
while ((t = index (t, ' ')) != NULL)
{
++t;
*t = toupper (t[0]);
}
domail (tmpfile);
}
}
fclose (input);
if (rm)
unlink (filename);
/* filedir (argv[k], 0, filename);
for (q = 1; q < a; q++)
filedir (argv[k], q, filename);
filedir (argv[k], a++, filename); */
}
++k;
}
}
changeit (groupname, oldchar, newchar)
char *groupname, oldchar, newchar;
{
char *tmp;
tmp = groupname;
while (*tmp != '\0')
{
if (*tmp == oldchar)
*tmp = newchar;
++tmp;
}
}
addnumber (newname)
char *newname;
{
int i, max;
char tmp1[100], filename[100];
max = 0;
strcpy (tmp1, newname);
strcat (tmp1, "/*.MSG");
filedir (tmp1, 0, filename);
while (filename[0] != '\0')
{
sscanf (filename, "%d.", &i);
if (i > max)
max = i;
filedir (tmp1, 1, filename);
}
++max;
sprintf (newname, "%s/%d.MSG", newname, max);
}
filecopy (oldname, newname, n)
char *oldname, *newname;
int n;
{
int in, out, c;
char buf[BUFSIZ];
in = open (oldname, O_RDONLY);
out = open (newname, O_CREAT+O_WRONLY);
if (!n)
write (out, &mess_head, sizeof (struct _msg));
while ((c = read (in, buf, BUFSIZ)) == BUFSIZ)
write (out, buf, BUFSIZ);
if (c != 0)
write (out, buf, c);
close (in);
close (out);
}
change_name (oldname, groupname)
char *oldname, *groupname;
{
char newname[100];
extern char *index ();
char *comma;
changeit (groupname, '.', '/');
comma = groupname;
while (comma != NULL)
{
strcpy (newname, "C:/FIDO/USENET/");
comma = index (groupname, ',');
if (comma != NULL)
*comma = '\0';
else
groupname[strlen(groupname)-1] = '\0';
strcat (newname, groupname);
addnumber (newname);
if (newname[0] != '\0')
{
printf (" It is becoming '%s'\n", newname);
filecopy (oldname, newname, 0);
}
if (comma != NULL)
groupname = comma + 1;
}
unlink (oldname);
}
domail (filename)
char *filename;
{
char newname[100];
extern char *index ();
char *comma;
strcpy (newname, "C:/FIDO/FIDOMAIL");
addnumber (newname);
if (newname[0] != '\0')
{
printf (" It is mail that will become '%s'\n", newname);
filecopy (filename, newname, 0);
}
unlink (filename);
}
/*
date.c
Author: Bob Hartman
Date: 6-5-85
This file implements a standardized date routine which is
callable from Manx AZTEC C-86 compiler. The format string
determines the way the date is to be formatted as follows:
%n - 3 character month name
%N - Full month name
%m - Month as 2 digits (zero filled if necessary)
%d - Day as 2 digits (zero filled if necessary)
%y - Year as 2 digits
%Y - Year as 4 digits
A % not followed by one of the above is ignored.
All other characters in the format specifier are
copied to the output string.
*/
/* Character used to delimit format specifiers in format strings */
#define ESCAPE_CHAR '%'
#define DOSINT 0x21
/* Month names for date() function */
static char *_months[12] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
/* Day of week names for date() function */
static char *_days[7] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
/*
date (fmt, d)
char *fmt;
char *d;
returns in d, the current date in the form specified by the fmt string
*/
date (fmt, d)
register char *fmt;
register char *d;
{
union REGS inregs, outregs;
char temp[5]; /* To hold date so it can be processed again */
int w, y, m, d1;
inregs.x.ax = 0x2a00;
(void) sysint (DOSINT, &inregs, &outregs);
w = outregs.h.al;
y = outregs.x.cx;
m = outregs.h.dh;
d1 = outregs.h.dl;
/* Now go through the format string */
while (*fmt != '\0')
{
if (*fmt != ESCAPE_CHAR)
*d++ = *fmt;
else
{
switch (*(++fmt))
{
case 'n':
sprintf (d, "%.3s", _months[m - 1]);
d += 3;
break;
case 'N':
sprintf (d, "%s", _months[m - 1]);
d += strlen (d);
break;
case 'm':
sprintf (d, "%02d", m);
d += 2;
break;
case 'd':
sprintf (d, "%02d", d1);
d += 2;
break;
case 'w':
sprintf (d, "%.3s", _days[w]);
d += 3;
break;
case 'W':
sprintf (d, "%s", _days[w]);
d += strlen (d);
break;
case 'y':
sprintf (temp, "%04d", y);
sprintf (d, "%.2s", temp+2);
d += 2;
break;
case 'Y':
sprintf (d, "%04d", y);
d += 4;
break;
default:
*d++ = *fmt;
}
}
++fmt;
}
*d = '\0'; /* Just to be sure that it is null terminated */
}
/*
time (fmt, t)
char *fmt;
char *t;
returns in t, the current time in the form specified by the fmt string
*/
time (fmt, t)
register char *fmt;
register char *t;
{
union REGS inregs, outregs;
int h, m, s, ms;
inregs.x.ax = 0x2c00;
(void) sysint (DOSINT, &inregs, &outregs);
h = outregs.h.ch;
m = outregs.h.cl;
s = outregs.h.dh;
ms = outregs.h.dl;
/* Now go through the format string */
while (*fmt != '\0')
{
if (*fmt != ESCAPE_CHAR)
*t++ = *fmt;
else
{
switch (*(++fmt))
{
/* hours (24 hour clock) */
case 'h':
sprintf (t, "%02d", h);
t += 2;
break;
/* hours (12 hour clock) */
case 'H':
sprintf (t, "%02d", (h % 12) ? (h % 12) : 12);
t += 2;
break;
/* minutes */
case 'm':
sprintf (t, "%02d", m);
t += 2;
break;
/* seconds */
case 's':
sprintf (t, "%02d", s);
t += 2;
break;
/* hundredths of a second */
case 't':
sprintf (t, "%02d", ms);
t += 2;
break;
/* am/pm indicator */
case 'i':
sprintf (t, "%s", (h < 12) ? "am" : "pm");
t += 2;
break;
/* AM/PM indicator */
case 'I':
sprintf (t, "%s", (h < 12) ? "AM" : "PM");
t += 2;
break;
default:
*t++ = *fmt;
}
}
++fmt;
}
*t = '\0'; /* Just to be sure that it is null terminated */
}
filedir (name, times, ret_str)
char *name;
int times;
char *ret_str;
{
char *ret_val;
bdos (0x1a, &sbuf);
if (times == 0) {
if (dos (0x4e, 0, ~ST_VLABEL, name, 0, 0) == -1)
sbuf.fname[0] = '\0';
strcpy (ret_str, sbuf.fname);
}
else {
if (dos (0x4f, 0, ~ST_VLABEL, name, 0, 0) == -1)
sbuf.fname[0] = '\0';
strcpy (ret_str, sbuf.fname);
}
}
strtrans (source, table)
register char *source, *table;
{
char *start_pointer;
/* Save the original source pointer
so that it can be returned */
start_pointer = source;
/* Step through the source string */
do {
/* Do the translation */
*source = table[*source];
} while (*++source);
/* Return the pointer to the result */
return (start_pointer);
}
/* This table contains character
translation codes for
converting upper case to
lower case */
static char low_table[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255
};
/*
* char *
* strlower (str)
* char *str;
*
* This function returns the string str with all upper case characters
* converted to lower case. It simply calls strtrans (in module
* strtrans.obj) with the above tranlation table.
*/
strlower (str)
register char *str;
{
return (strtrans (str, low_table));
}